﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoHibernate.API;

namespace AutoHibernate.Impl
{
    public class TimeConversionImpl : ITimeConversion
    {
        public int ConvertToMilliSeconds(string value, TimeUnit unit)
        {
            double parsedValue = double.Parse(value);
            switch (unit)
            {
                case TimeUnit.Hours:
                    return (int)TimeSpan.FromHours(parsedValue).TotalMilliseconds;

                case TimeUnit.Minutes:
                    return (int)TimeSpan.FromMinutes(parsedValue).TotalMilliseconds;

                case TimeUnit.Seconds:
                    return (int)TimeSpan.FromSeconds(parsedValue).TotalMilliseconds;
            }
            throw new ArgumentException("Unknown argument");
        }

        public int CalculateAbsoluteDifferenceInMilliSeconds(DateTime dateTime1, DateTime dateTime2)
        {
            long remainingTime = Math.Abs(dateTime1.Ticks - dateTime2.Ticks);
            return (int)TimeSpan.FromTicks(remainingTime).TotalMilliseconds;
        }
    }
}
